{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Day 1：编程环境搭建与基础语法（3学时）\n",
    "\n",
    "**周贤中**\n",
    "\n",
    "## 1. Python简介与开发环境搭建（Anaconda）\n",
    "\n",
    "### 1.1 Python核心特性演示"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 整型示例\n",
    "age = 25                   # 十进制\n",
    "binary_num = 0b1101        # 二进制 (13)\n",
    "hex_num = 0x1a             # 十六进制 (26)\n",
    "\n",
    "# 浮点型示例\n",
    "price = 3.1415            \n",
    "sci_num = 2.5e-3          # 0.0025\n",
    "\n",
    "# 字符串示例\n",
    "name = \"DeepSeek\"         \n",
    "multiline = '''第一行\n",
    "第二行'''\n",
    "raw_str = r\"换行符:\\n不会转义\"\n",
    "\n",
    "# 布尔型示例\n",
    "is_valid = True           \n",
    "is_empty = False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "128\n"
     ]
    }
   ],
   "source": [
    "# 类型转换示例\n",
    "quantity = \"123\"\n",
    "print(int(quantity) + 5)    # 128\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "pi_str = str(3.1415926)    # \"3.1415926\"\n",
    "mix_type = 15 + 3.0        # 自动转换为浮点型"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- 浮点精度处理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "from decimal import Decimal\n",
    "precise_float = Decimal('0.1') + Decimal('0.2')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- 布尔转换规则"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[False, True, False, True, False, True]\n"
     ]
    }
   ],
   "source": [
    "values = [0, 1, \"\", \"Hello\", [], [1]]\n",
    "print([bool(v) for v in values])  # [False, True, False, True, False, True]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Jpyter notebook"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "13\n",
      "7.5\n",
      "16\n",
      "True\n",
      "False\n",
      "安全通过短路测试: False\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "<>:8: SyntaxWarning: \"is\" with 'int' literal. Did you mean \"==\"?\n",
      "<>:8: SyntaxWarning: \"is\" with 'int' literal. Did you mean \"==\"?\n",
      "C:\\Users\\zhoux\\AppData\\Local\\Temp\\ipykernel_23028\\3407709980.py:8: SyntaxWarning: \"is\" with 'int' literal. Did you mean \"==\"?\n",
      "  print(5 is 5.0)  # False → 类型不同\n"
     ]
    }
   ],
   "source": [
    "# 算术运算符\n",
    "print(10 + 3)   # 13 → 加法\n",
    "print(10 - 2.5) # 7.5 → 减法\n",
    "print(2 ** 4)   # 16 → 幂运算\n",
    "\n",
    "# 比较运算符\n",
    "print(5 == 5.0)  # True → 值等判断\n",
    "print(5 is 5.0)  # False → 类型不同\n",
    "\n",
    "# 逻辑运算短路特性\n",
    "result = False and (1/0)  # 不会触发ZeroDivisionError，因为短路\n",
    "print(\"安全通过短路测试:\", result)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
